/**
 * @name 岗位的js类
 * @author Yang
 * @date 2018-07-10
 */
var Position=function () {

    /**
     * 初始化表单的函数
     *
     */
    var addInitHandler=function () {
        console.log("this is position");
        $('.dropdown-toggle').on("click",function () {
            $('#addPosition').modal('show');
        })
    };

    /**
     * 校验表单
     *
     */
    var validateHandler= function () {
        var $form= $('#submitForm');
        $form.validate({
            rules:{
                name:{
                    required:true,
                    minlength:2,
                    maxlength:20,
                    remote:{
                        type:"get",
                        url:'validate'
                    }
                }
            },
            messages:{
                name:{
                    required:"必填",
                    minlength:"至少要2个字符",
                    maxlenhth:"最多20个字符",
                    remote:"岗位已经存在"
                }
            },
            submitHandler:function (form) {
                var params={};
                params.name= $("#positionName").val();
                params.content= $("#content").val();
                params= JSON.stringify(params);
                $.ajax({
                    type:"post",
                    url:"submit",
                    data:{"params":params},
                    dataType:"json",
                    success:function (data) {
                        Common.alert(data);
                        setTimeout(function () {
                            location.reload(true);
                        },1500);
                    }
                })
            }
        })
    };

    return {
       submit:function () {
           addInitHandler();
           validateHandler();
       }
    }
}();